package cn.lctvu.service;

import cn.lctvu.bean.User;
import cn.lctvu.dao.UserDao;

import java.sql.SQLException;
import java.util.List;

public class UserService {
    private UserDao userDao=new UserDao();
    public User getUserByNameAndPass(String username,String password){
        try {
            return  userDao.getUserByNameAndPass(username,password);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 删除用户
     * @param id
     * @return
     */
    public boolean deleteUserById(int id){
        try {
            return userDao.deleteUserById(id);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return false;
    }

    /**
     * 修改用户
     * @param user
     * @return
     */
    public boolean updateUser(User user){
        try {
            return userDao.updateUser(user);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return false;
    }

    /**
     * 查询所有用户
     * @return
     */
    public List<User> findAllUser(){
        try {
            return userDao.findAllUser();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 根据id查询用户
     * @param id
     * @return
     */
    public User findUserById(int id){
        try {
           return userDao.findUserById(id);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 添加用户
     * @param user
     * @return
     */
    public boolean addUser(User user){
        try {
            return userDao.addUser(user);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return false;
    }
}
